<?php
class Gamer_model extends Base_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->model('redis_model');
    }

    public function preregister($data=array())
    {
        $res = $this->db->get_where('mod_gamer',array('telNum'=>$data['telNum']))->row_array();
        if (empty($res)){
            $this->db->insert('mod_gamer',$data);
            return $this->db->insert_id();
        }else{
            return false;
        }
    }

    public function register($updatewhere,$user,$gamerinfo)
    {
        $this->db->trans_begin();
        $this->db->insert('mod_gamer_info', $gamerinfo);
        $this->db->update('mod_user',$user,$updatewhere);
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            return false;
        }
        else
        {
            $this->db->trans_commit();
            return true;
        }
    }

    public function getCityList()
    {
        $res = $this->redis_model->get('data:city');
        return igbinary_unserialize($res);
    }

    public function getAreaListBycity($cityid)
    {
        $data = $this->redis_model->zrange('city:'.$cityid,0,-1,true);
        $res = '';
        foreach ($data as $k=>$v)
        {
            $res[] = array('area'=>$k,'areaid'=>$v);
        }
        return $res;
    }
}